#pragma once

#include "../umlmodel_global.h"

#include <memory>
#include <vector>

#include "InvocationAction.h"

using std::make_shared;
using std::shared_ptr;
using std::vector;

namespace uml {
class OutputPin;
class Parameter;

/// <summary>
/// CallAction
/// CallAction is an abstract class for Actions that invoke a Behavior with given
/// argument values and (if the invocation is synchronous) receive reply values.
/// </summary>
class UMLMODEL_EXPORT CallAction : public InvocationAction {

public: // Constructors and destructors
    explicit CallAction(const QString& umlType="uml::CallAction");

public: // JsonSerializable override
    void fromJson(const QJsonObject& json, QStringList& errorList) override;
    void toJson(QJsonObject& json) override;

public: // Methods
    /// <summary>
    /// inputParameters
    /// Return the in and inout ownedParameters of the Behavior or Operation being
    /// called. (This operation is abstract and should be overridden by subclasses of
    /// CallAction.)
    /// </summary>
    virtual shared_ptr<vector<Parameter>> inputParameters() const = 0;

    /// <summary>
    /// outputParameters
    /// Return the inout, out and return ownedParameters of the Behavior or Operation
    /// being called. (This operation is abstract and should be overridden by subclasses
    /// of CallAction.)
    /// </summary>
    virtual shared_ptr<vector<Parameter>> outputParameters() const = 0;

public: // Properties
    /// <summary>
    /// isSynchronous getter
    /// If true, the call is synchronous and the caller waits for completion of the
    /// invoked Behavior. If false, the call is asynchronous and the caller proceeds
    /// immediately and cannot receive return values.
    /// </summary>
    bool isSynchronous() const;

    /// <summary>
    /// isSynchronous setter
    /// If true, the call is synchronous and the caller waits for completion of the
    /// invoked Behavior. If false, the call is asynchronous and the caller proceeds
    /// immediately and cannot receive return values.
    /// </summary>
    void setIsSynchronous(bool value);

    /// <summary>
    /// results getter
    /// The OutputPins on which the reply values from the invocation are placed (if the
    /// call is synchronous).
    /// </summary>
    vector<shared_ptr<OutputPin>>& results();

private: // Fields
    /// <summary>
    /// isSynchronous
    /// If true, the call is synchronous and the caller waits for completion of the
    /// invoked Behavior. If false, the call is asynchronous and the caller proceeds
    /// immediately and cannot receive return values.
    /// </summary>
    const static bool isSynchronous_default_;
    bool isSynchronous_= isSynchronous_default_;

    /// <summary>
    /// results
    /// The OutputPins on which the reply values from the invocation are placed (if the
    /// call is synchronous).
    /// </summary>
    vector<shared_ptr<OutputPin>> results_;

};

} // namespace uml
